#ifndef OGREWIDGET_H
#define OGREWIDGET_H

#include <QWidget>
#include "ui_ogrewidget.h"
#include <OgreTimer.h>
#include <atomic>
class MeshData;
class RoadMileLine;

namespace Ogre
{
	class DefaultRaySceneQuery;

}
namespace OgreModel
{
	class GraphicsSystem;
	class GameStateMain;
}
class OgreWidget : public QWidget
{
	Q_OBJECT
public:
signals :
	void signSelChange(const ZMString& strObjName);
public:
	OgreWidget(QWidget *pTop,QWidget *parent = 0);
	~OgreWidget();
	QPaintEngine* paintEngine() const;
	void Init();

	virtual	void paintEvent(QPaintEvent *);

	void AddMeshData(const ZMString&parentNodeName, const ZMString&strNodeName, const ZMString&strMatName, const MeshData& data);

	void ChangeMaterial(bool isWire);

	void RemoveNodeData(const ZMString&strNodeName);
	void CreateOrGetNode(const Ogre::String&strParentNodeName, const Ogre::String&strNodeName);
	void ChangeObjMaterial(const ZMVector<ZMString>& vObjName, const ZMString& materialName);
	void SetCamera(const ZMPoint3D& position, const ZMPoint3D& look);

	void BindRoadMileLine(SharedPointer<RoadMileLine> pMile);

	void OffsetObj(const ZMString& objName, const ZMPoint3D& offsetAxis, const ZMReal& fOffsetValue, bool isAbs = true);

	void RotateObj(const ZMString& objName, const ZMPoint3D& pntOrign, const ZMPoint3D& rAxis, const ZMReal& fAngle, bool isAbs = true);

protected:
	void mouseDoubleClickEvent(QMouseEvent*);
	virtual bool event(QEvent *event);
protected slots:
	void Render();
private:
	QWidget * m_pTop;
	bool m_isInit;
	Ui::OgreWidget ui;
	boost::shared_ptr<OgreModel::GraphicsSystem> m_pGraphicsSystem;
	boost::shared_ptr<OgreModel::GameStateMain> m_pGameState;
	std::atomic<bool> m_isNeedRender;
	Ogre::Timer m_Timer;
	unsigned long m_startTime;
};

#endif // OGREWIDGET_H
